**************************************************
********* Table 3: Likelihood of Non-Incumbent ***
********* Presence on General Election Ballot ****
**************************************************

do "do_files/prep_GRACE_data/load_prep_GRACE_data.do"
do "do_files/prep_GRACE_data/ballot_level_prep.do"

* Also Appendix A3 in the appendix (full results report)
* NOTE: data collapsed to ballot level 

* all districts model weights
cem latpoppct (1	2	3	4	5	6	7	8	9	10	11	12	13	14	15	16	17	18	19	20	21	22	23	24	25	26	27	28	29	30	31	32	33	34	35	36	37	38	39	40	41	42	43	44	45	46	47	48	49	50	51	52	53	54	55	56	57	58	59	60	61	62	63	64	65	66	67	68	69	70	71	72	73	74	75	76	77	78	79	80	81	82	83	84	85	86	87	88	89	90	91	92	93	94	95	96	97	98	99	100) demvoteshareballot_2020, treatment(ballot_latallpres)

rename cem_weights all_districts_cem_weights

* MMD only model weights

cem latpoppct (1	2	3	4	5	6	7	8	9	10	11	12	13	14	15	16	17	18	19	20	21	22	23	24	25	26	27	28	29	30	31	32	33	34	35	36	37	38	39	40	41	42	43	44	45	46	47	48	49	50	51	52	53	54	55	56	57	58	59	60	61	62	63	64	65	66	67	68	69	70	71	72	73	74	75	76	77	78	79	80	81	82	83	84	85	86	87	88	89	90	91	92	93	94	95	96	97	98	99	100) demvoteshareballot_2020 if majpocpop == 1, treat(ballot_latallpres) 

rename cem_weights mmd_only_cem_weights

* MMD only model weights with latino majority district observations excluded
cem latpoppct (1	2	3	4	5	6	7	8	9	10	11	12	13	14	15	16	17	18	19	20	21	22	23	24	25	26	27	28	29	30	31	32	33	34	35	36	37	38	39	40	41	42	43	44	45	46	47	48	49	50	51	52	53	54	55	56	57	58	59	60	61	62	63	64	65	66	67	68	69	70	71	72	73	74	75	76	77	78	79	80	81	82	83	84	85	86	87	88	89	90	91	92	93	94	95	96	 97	98	99	100) demvoteshareballot_2020 if latmaj!=1 & majpocpop == 1 , treat(ballot_latallpres)
rename cem_weights mmd_exclude_latmaj_cem_weights


* All districts model: Latina

eststo, title(Latina): quietly probit ballot_newlatwpres  afampoppct asampoppct latpoppct    tlimit  legprof  distrepubstr  openelect  multimem  candperseat allincfmt educcolldeg unemppct stateyear_inclatpct [iweight=all_districts_cem_weights]

* All districts model: Latino
eststo, title(Latino): quietly probit ballot_newlatmpres  afampoppct asampoppct latpoppct    tlimit  legprof  distrepubstr  openelect  multimem  candperseat allincfmt educcolldeg unemppct stateyear_inclatpct [iweight=all_districts_cem_weights]

* MMD only model: Latina
eststo, title(Latina): quietly probit ballot_newlatwpres  afampoppct asampoppct latpoppct    tlimit  legprof  distrepubstr  openelect  multimem  candperseat allincfmt educcolldeg unemppct stateyear_inclatpct [iweight=mmd_only_cem_weights]

* MMD only model: Latino
eststo, title(Latino): quietly probit ballot_newlatmpres  afampoppct asampoppct latpoppct    tlimit  legprof  distrepubstr  openelect  multimem  candperseat allincfmt educcolldeg unemppct stateyear_inclatpct [iweight=mmd_only_cem_weights]

* MMD model with Latino MMDs excluded: Latina
eststo, title(Latina): quietly probit ballot_newlatwpres  afampoppct asampoppct latpoppct    tlimit  legprof  distrepubstr  openelect  multimem  candperseat allincfmt educcolldeg unemppct stateyear_inclatpct [iweight=mmd_exclude_latmaj_cem_weights]

* MMD model with Latino MMDs excluded: Latino
eststo, title(Latino): quietly probit ballot_newlatmpres  afampoppct asampoppct latpoppct    tlimit  legprof  distrepubstr  openelect  multimem  candperseat allincfmt educcolldeg unemppct stateyear_inclatpct [iweight=mmd_exclude_latmaj_cem_weights]


estout, cells(b(star fmt(3)) se(par fmt(2))) legend label varlabels(_cons Constant) stats(N, fmt(0)) mgroups("Any District" "MMDs" "MMDs, Excluding Latino Majority Districts", pattern(1 0 1 0 1 0))

* clear eststo for displaying future tables
eststo clear

* pausing for users who might be looping through all replication files
pause

